<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
?>

<?php
$page_current['title'] 				= isset($page_current['title']) ? $page_current['title'] : "";
$page_current['page_title'] 		= isset($page_current['page_title']) ? $page_current['page_title'] : "";
$page_current['meta_keywords'] 		= isset($page_current['meta_keywords']) ? $page_current['meta_keywords'] : "";
$page_current['meta_description'] 	= isset($page_current['meta_description']) ? $page_current['meta_description'] : "";
$page_current['content'] 			= isset($page_current['content']) ? $page_current['content'] : "";
$page_current['hook'] 				= isset($page_current['hook']) ? $page_current['hook'] : "";
$page_current['rendertype'] 		= isset($page_current['rendertype']) ? $page_current['rendertype'] : "";
$page_current['contenttype'] 		= isset($page_current['contenttype']) ? $page_current['contenttype'] : "";
?>

<!-- -- START HTML FORM -- -->
<?php if( $action == 'create' || $action == 'createsnip'):?>
<form method="post" action="<?php echo $this->baseUrl("/page/manage/{$action}");?>" class="pagemanager_form">
<?php else: ?>
<form method="post" action="<?php echo $this->baseUrl("/page/manage/{$action}/{$page_id}");?>" id="auto_chk_submit" class="pagemanager_form" >
<?php endif;?>


    <!-- -- CREATE TOP TOOL BAR -- -->
    <?php 
    App::Helper('Toolbar')->setTitle("Static page manager")->setBtnSave()->setBtnDelete()->setBtnfileManager();
    if(isset($page_id) && isset($static_page_arr[$page_id]))
    {
        App::Helper('Toolbar')->setBtnCustomHtml(App::Helper("Html")->ButtonTag("Button[View][Page]","View Page",array("onclick"=>"document.location='" . $this->baseurl("/page/view/{$static_page_arr[$page_id]}") . "';")));
    }
    App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'static_page_save_top',"page"=>$page_current));
    ?>


    <!--  -- PAGE TYPE SELECTOR -- -->
    <input type="hidden" name="data[Page][contenttype]" value="<?php
    if($action == 'create') echo appRain_Base_Modules_PageManager::CONTENT;
    elseif($action == 'createsnip') echo appRain_Base_Modules_PageManager::SNIP;
    else echo $page_current['contenttype'] ;
    ?>" />

    <!-- -- CREATE FIELDS -- -->
    <?php
        $Grid = App::Module('DataGrid')->setDisplay('FormListing');
        if( $action == 'create' || $action == 'createsnip')
        {
            $Grid->addRow($this->__("Name"),App::Helper("Html")->inputTag("data[Page][name]","",array("class" => "app_input check_notempty","id" => "page_name")));
        }
        else
        {
            if($page_current['contenttype'] == 'Snip')
            {
                $Grid->addRow($this->__("Select Page"),App::Helper("Html")->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")))
                     ->addRow("&nbsp;","{{name=UI type=staticpage name={$page_current['name']}}} <a href=\"javascript:void(0)\"  id=\"help-dialog-modal-open\">Help?</a> <a href=\"#\" id=\"dialog-modal-open\">All Codes?</a>");
            }
            else
            {
                $Grid->addRow($this->__("Select Page"),App::Helper("Html")->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")) .  App::Module('AdminpanelUI')->getPagemanagerHookList($this->theme,$page_current))
                     ->addRow("&nbsp;","{{name=UI type=staticpage name={$page_current['name']} autoformat=off}} <a href=\"javascript:void(0)\"  id=\"help-dialog-modal-open\">Help?</a> <a href=\"#\" id=\"dialog-modal-open\">All Codes?</a>");
            }
        }

        if( $this->get_config('disable_page_meta_options') != "Yes" && $page_current['contenttype'] != 'Snip' && $action != 'createsnip')
        {
            $Grid->addRow($this->__("Page Meta Title"),App::Helper("Html")->textareaTag('data[Page][page_title]', $page_current['page_title'],array("class" => "app_input","id" => "page_title")))
                 ->addRow($this->__("Meta Keywords"),App::Helper("Html")->textareaTag('data[Page][meta_keywords]', $page_current['meta_keywords'],array("class" => "app_input","id" => "meta_keywords")))
                 ->addRow($this->__("Meta Descriptions"),App::Helper("Html")->textareaTag('data[Page][meta_description]', $page_current['meta_description'],array("style"=>"overflow:none","class" => "app_input","id" => "meta_description")));
        }


        if($page_current['contenttype'] == 'Snip' || $action == 'createsnip')
        {
            if(trim($page_current['content'])=="")
            {
                $page_current['content'] =
'<?php
/**
 * Write PHP Code
 *
 * Example:
 * $Config = App::Config()->siteInfo();
 * pre($Config);
 */
?>';
            }
            $Grid->addRow("Content",App::Helper("Html")->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "22","class" => "lined","id" => "page_content")));
        }
        else
        {
            $Grid->addRow("Title",App::Helper("Html")->inputTag('data[Page][title]', $page_current['title'],array("class" => "app_input","id" => "title")));
            $Grid->addRow("Content",App::Helper("Html")->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "32","class" => "textarea richtexteditor","id" => "page_content")));
        }

        $Grid->Render();
    ?>

    <!-- -- HIDDEN PAGE CODE LIST -- -->
    <?php    echo App::Module('AdminPanelUi')->pageCodesList('Html'); ?>

    <?php App::Helper('Toolbar')->setBtnSave()->setBtnBack()->setFormJustified(true)->Render(array('code'=>'static_page_save_bottom',"page"=>$page_current));?>

</form>

<?php if( $action != 'create' && $action != 'createsnip'):?>
<div id="help-dialog-modal">

    <strong><?php echo $this->__("Help:");?></strong>
    <br /><br />

    <?php echo $this->__("- Copy this code in other page content to render inside.");?><br /><br />
    <?php if($page_current['contenttype'] == 'Snip' || $action == 'createsnip'):?>
    <?php echo $this->__("- Use 'Snip' to execute PHP command.");?><br /><br />

    <strong><?php echo $this->__("NOTE:");?></strong>
    <?php echo $this->__("- To access any resource please use 'App' Factory.");?><br />
    <br />
    <?php echo $this->__("Example:");?>
    <pre style="background:#FFF">&lt;?php
   $Config = App::Config()->siteInfo();
   pre($Config);
?&gt;</pre>
</div>
    <?php else:?>
    <?php echo $this->__("- Select 'Auto Render' to set content in different 'Hook Position' or 'Menu'.");?><br /><br />
    <?php echo $this->__("- Enable 'Show Hook Positions' from 'System >> Configuration' to view positions.");?><br /><br />
    <?php echo $this->__("- Use 'Snip' to execute PHP command.");?><br /><br /><br />

    <strong><?php echo $this->__("Render Type");?></strong><br /><br />
    <?php echo nl2br($this->__("Text: Render HTML Content\n Link : Page Direct Link\n Smart Link: Friendly URL by Page Name"));?>
    <?php endif;?>
<?php endif;?>
<?php App::Helper('JavaScript')->appForm('.pagemanager_form'); ?>

<!-- -- JS TO SWITCH PAGE -- -->
<?php if( $action != 'create'):?>
<script type="text/javascript">
        
        // Create Modal
        jQuery(document).ready(function (){
            jQuery("#help-dialog-modal").dialog({
            title :'Guide Line',
            autoOpen: false,
            width:500,
            modal: true
        });
        // Display Modal
        jQuery("#help-dialog-modal-open").click(function () {
            jQuery("#help-dialog-modal").dialog("open");
            return false;
        });
        // Switch Page
        jQuery('#page_id').change(function(){
            if( this.value != ''){
                window.location = siteInfo.baseUrl + '/page/manage/update/' + this.value;
            }
        });
    });
</script>
<?php endif; ?>